/**
 * 
 */
package formulavendasweb.filter;

import java.io.IOException;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;

import br.com.formulavendas.domainmodel.Usuario;

/**
 * @author Fernando
 *
 */
public class UsuarioPagesFilter extends AbstractFilter implements Filter {
	@Override
    public void destroy() { 
    }
 
    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) request;
        Usuario user = (Usuario) req.getSession(true).getAttribute("usuario");
 
        if(!user.isUsuario() && !user.isAdmin()){
            accessDenied(request, response, req);
            return;
        }
 
        chain.doFilter(request, response);
    }
 
    @Override
    public void init(FilterConfig arg0) throws ServletException { 
    }
}
